package com.yjhz.ruleengine.demos.service;

import com.yjhz.ruleengine.demos.entity.Order;
import lombok.RequiredArgsConstructor;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class OrderService {

    private final KieSession kieSession;

    public Order applyDiscount(Order order) {
        // 将订单对象插入到Drools工作内存中
        kieSession.insert(order);
        // 执行规则
        kieSession.fireAllRules();
        return order;
    }
}
